import HoneyBeesBase from "src/Ldz_GameCore/HoneyBee/HoneyBeeManager/HoneyBeesBase";
import BuffBase from "./BuffBase";
import BuffTypeManager from "./BuffTypeManager";

export default class BuffManager {

    // public states: Map<BuffBase, any> = new Map<BuffBase, any>();//人物拥有的所有状态集合  字典 key=Type value=PlayerStateBase
    BuffMap: Map<string, BuffBase> = new Map<string, BuffBase>();
    public m_SelfObj: Laya.Sprite3D;

    public m_SoldiersBase: HoneyBeesBase;
    /**初始化Buff管理器 */
    InitBuffManager(SelfObj: Laya.Sprite3D, SoldiersBase: HoneyBeesBase) {
        this.m_SelfObj = SelfObj;
        this.m_SoldiersBase = SoldiersBase;
    }
    /**添加Buff */
    AddBuffState(_BuffBase: string, _Target: HoneyBeesBase) {

        if (BuffTypeManager.Instance.DoesTheBuffTypeExist(_BuffBase)) {
            if (this.BuffMap.has(_BuffBase)) {
                let Buf = this.BuffMap.get(_BuffBase);
                // console.log(Buf);
                Buf.RefreshBuff();
            } else {
                let buf = new (BuffTypeManager.Instance.GetTypeByName(_BuffBase))();
                this.BuffMap.set(_BuffBase, buf);
                buf.InitBuffBase(this.m_SoldiersBase, _Target);
                buf.BuffOccur();
            }
        }
    }

    /** */
    CheckBuffbase(_BuffBase: BuffBase) {
        // for (let i = 0; i < this.BuffMap.length; i++) {
        //     if (this.BuffMap[i] == _BuffBase) {
        //         return this.BuffMap[i];
        //     }
        // }
        // return null;
    }

    /**收到攻击 */
    BuffBeHurt() {
        this.BuffMap.forEach((Value, Key) => {
            Value.BuffBeHurt();
        });
    }
    /**攻击时*/
    BuffOnHit() {

        this.BuffMap.forEach((Value, Key) => {
            Value.BuffOnHit();
        });

    }
    /**被杀死时*/
    BuffBeforeKilled() {
        this.BuffMap.forEach((Value, Key) => {
            Value.BuffBeforeKilled();
        });
    }

    /**敌人死亡时*/
    BuffAfterKilled() {
        this.BuffMap.forEach((Value, Key) => {
            Value.BuffAfterKilled();
        });
    }

    /**更新Buff */
    BuffUpdate() {
        let TempBuffMap: Map<string, BuffBase> = new Map<string, BuffBase>();
        this.BuffMap.forEach((Value, Key) => {
            if (Value != null && !Value.IsDestory) {
                Value.BuffOnTick();
                TempBuffMap.set(Key, Value)
            }
        });
        this.BuffMap = TempBuffMap;
    }

}